package com.vincent.common.utils;

import com.vincent.common.enums.SessionEnum;
import com.vincent.model.Admin;
import org.springframework.util.Assert;

import javax.servlet.http.HttpSession;

/**
 * Session工具类
 */
public class SessionUtil {
    /**
     * 清除session中的对象
     * @param session
     */
    public static void clearSession(HttpSession session){
        Assert.notNull(session);
        String[] sessionNameArray = SessionEnum.getAllSessionName();
        for (String s : sessionNameArray) {
            session.removeAttribute(s);
        }
    }

    public static Admin getAdmin(HttpSession session){
        Object adminObj = session.getAttribute(SessionEnum.ADMIN.getCode());
        return (Admin) adminObj;
    }
}
